package com.qipay.baas.mapper;

import static org.apache.ibatis.jdbc.SqlBuilder.BEGIN;
import static org.apache.ibatis.jdbc.SqlBuilder.INSERT_INTO;
import static org.apache.ibatis.jdbc.SqlBuilder.SET;
import static org.apache.ibatis.jdbc.SqlBuilder.SQL;
import static org.apache.ibatis.jdbc.SqlBuilder.UPDATE;
import static org.apache.ibatis.jdbc.SqlBuilder.VALUES;
import static org.apache.ibatis.jdbc.SqlBuilder.WHERE;

import com.qipay.baas.model.CpChannel;

public class CpChannelSqlProvider {

    public String insertSelective(CpChannel record) {
        BEGIN();
        INSERT_INTO("cp_channel");
        
        if (record.getCpId() != null) {
            VALUES("cp_id", "#{cpId,jdbcType=BIGINT}");
        }
        
        if (record.getChannelType() != null) {
            VALUES("channel_type", "#{channelType,jdbcType=TINYINT}");
        }
        
        if (record.getFeeRecharge() != null) {
            VALUES("fee_recharge", "#{feeRecharge,jdbcType=DECIMAL}");
        }
        
        if (record.getRateAdvince() != null) {
            VALUES("rate_advince", "#{rateAdvince,jdbcType=DECIMAL}");
        }
        
        if (record.getState() != null) {
            VALUES("`state`", "#{state,jdbcType=TINYINT}");
        }
        
        if (record.getUpdateDate() != null) {
            VALUES("update_date", "#{updateDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCreateDate() != null) {
            VALUES("create_date", "#{createDate,jdbcType=TIMESTAMP}");
        }
        
        return SQL();
    }

    public String updateByPrimaryKeySelective(CpChannel record) {
        BEGIN();
        UPDATE("cp_channel");
        
        if (record.getCpId() != null) {
            SET("cp_id = #{cpId,jdbcType=BIGINT}");
        }
        
        if (record.getChannelType() != null) {
            SET("channel_type = #{channelType,jdbcType=TINYINT}");
        }
        
        if (record.getFeeRecharge() != null) {
            SET("fee_recharge = #{feeRecharge,jdbcType=DECIMAL}");
        }
        
        if (record.getRateAdvince() != null) {
            SET("rate_advince = #{rateAdvince,jdbcType=DECIMAL}");
        }
        
        if (record.getState() != null) {
            SET("`state` = #{state,jdbcType=TINYINT}");
        }
        
        if (record.getUpdateDate() != null) {
            SET("update_date = #{updateDate,jdbcType=TIMESTAMP}");
        }
        
        if (record.getCreateDate() != null) {
            SET("create_date = #{createDate,jdbcType=TIMESTAMP}");
        }
        
        WHERE("id = #{id,jdbcType=BIGINT}");
        
        return SQL();
    }
}